Bluetooth: af_bluetooth: Fix Use-After-Free in bt_sock_recvmsg
authorHyunwoo Kim <v4bel@theori.io>
Sat, 9 Dec 2023 10:55:18 +0000 (05:55 -0500)
committerSalvatore Bonaccorso <carnil@debian.org>
Sat, 30 Dec 2023 09:31:20 +0000 (10:31 +0100)
commitcd9f0df0dd327629d00aab298cb38502da18fea3
treee7580bf98dd143fb505b87ebfa3e9f3c9e404782
parent1a88ee8c4fae9f5fa53bac68ddcb0b02b64d6097
Bluetooth: af_bluetooth: Fix Use-After-Free in bt_sock_recvmsg

Origin: https://git.kernel.org/linus/2e07e8348ea454615e268222ae3fc240421be768
Bug-Debian-Security: https://security-tracker.debian.org/tracker/CVE-2023-51779

This can cause a race with bt_sock_ioctl() because
bt_sock_recvmsg() gets the skb from sk->sk_receive_queue
and then frees it without holding lock_sock.
A use-after-free for a skb occurs with the following flow.
```
bt_sock_recvmsg() -> skb_recv_datagram() -> skb_free_datagram()
bt_sock_ioctl() -> skb_peek()
```
Add lock_sock to bt_sock_recvmsg() to fix this issue.

Cc: stable@vger.kernel.org
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Hyunwoo Kim <v4bel@theori.io>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Gbp-Pq: Topic bugfix/all
Gbp-Pq: Name Bluetooth-af_bluetooth-Fix-Use-After-Free-in-bt_sock.patch
net/bluetooth/af_bluetooth.c